<link rel="stylesheet" href="/ceca_two/css/costShareOne.css" />
<!--header-->
<!--# include virtual="/ceca_two/common/html/header.html"-->
<!--# include virtual="/ceca_two/modules/quota/base/policyShare.html"-->
<style type="text/css">
	input::-webkit-outer-spin-button,
	input::-webkit-inner-spin-button {
		-webkit-appearance: none;
	}
	
	input[type="number"] {
		-moz-appearance: textfield;
	}
	
	tr td:last-child {
		overflow: hidden;
	}
	
	tr td:last-child span {
		width: 230px;
		display: block;
		overflow: hidden;
		text-indent: 2em;
		text-overflow: ellipsis;
		line-height: 40px;
		max-height: 40px;
		white-space: nowrap;
	}
	
	.fill {
		border: 1px solid #ff3030!important;
	}
	
	select {
		width: 25%;
		height: 100%;
		display: block;
		border: none;
		box-sizing: border-box;
		text-indent: 20px;
		float: left;
	}
</style>
<h1 class="shareName">政策法规</h1>
<table class="shareTable">
	<tr>
		<td style="width: 10%"></td>
		<td class="property" style="width: 90%"></td>
	</tr>
	<tr>
		<td>标题</td>
		<td class="property">
			<input type="text" id="titles" name="titles" value="" placeholder="请输入标题" />
		</td>
	</tr>
	<tr>
		<td>文号</td>
		<td class="property">
			<input type="text" id="keyword" name="keyword" value="" placeholder="请输入文号" />
		</td>
	</tr>
	<tr>
		<td>法规分类</td>
		<td class="property proL" id="field">
			<select name="firstField" id="firstField"></select>
			<select name="secondField" id="secondField" style="display: none;"></select>
			<select name="thirdField" id="thirdField" style="display: none;"></select>
			<select name="fourthField" id="fourthField" style="display: none;"></select>
		</td>
	</tr>
	<tr>
		<td>发文机关</td>
		<td class="property proL">
			<select name="authors" id="authors"></select>
		</td>
	</tr>
	<tr>
		<td></td>
		<td class="property proL">
			<div id="selectedAuthors"></div>
		</td>
	</tr>
	<tr>
		<td>发布时间</td>
		<td class="property">
			<div class="layui-input-block" style="margin-left: 10px">
				<input class="layui-input" onclick="layui.laydate({elem: this, festival: true})" placeholder="选择日期" style="border: none;cursor: pointer;" name="openTime" id="openTime">
			</div>
		</td>
	</tr>
	<tr>
		<td>生效时间</td>
		<td class="property">
			<div class="layui-input-block" style="margin-left: 10px">
				<input class="layui-input" onclick="layui.laydate({elem: this, festival: true})" placeholder="选择日期" style="border: none;cursor: pointer;" name="effectiveTime" id="effectiveTime">
			</div>
		</td>
	</tr>
	<tr>
		<td>时效性</td>
		<td class="property">
			<select name="timeliness" id="timeliness">
				<option value="现行有效">现行有效</option>
				<option value="已修订">已修订</option>
				<option value="已失效/废止">已失效/废止</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>内容</td>
		<script id="context" name="context" type="text/plain" style="width:100%;height:800px;text-align: left;background: #fff!important;"></script>
	</tr>
</table>
<div class="shareCostBtn">
	<div class="saveBtn" style="margin: 50px 20px 50px 477px;">
		<a onclick="history.go(-1);" href="javascript:;">返回</a>
	</div>
	<div class="nextBtn" style="cursor: pointer;">
		<a id="submit">提交</a>
	</div>
</div>
</div>
</div>
<div id="tip" style="width: 1240px;padding: 0 0 20px;color: red;text-align: center;background: #fff;display: none;margin: 0 auto;"></div>
<!--底部-->
<!--# include virtual="/ceca_two/common/html/footer.html"-->
<script type="text/javascript" src="/ceca_two/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/ceca_two/lib/ueditor/1.4.3/ueditor.all.js">
</script>
<script type="text/javascript" src="/ceca_two/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script>
function getCookie(name){ 
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg)){
    	return unescape(arr[2]);
    }else{
    	window.location.href ='/user/modules/login/login.html'
    	return null; 
	} 
}
getCookie("username");
</script>
<script>
	layui.use(['laydate', 'sharecity','layer'], function() {
		layer = layui.layer;
		var fields = [];
		$.post("/guidance_service/front/policies/field/search.do", {}, function(data) {
			fields = data.data;
			var html = "";
			fields.forEach(function(item) {
				if(item.fieldParantId == "1") {
					html += "<option value=" + item.fieldId + " data-fieldParantId=" + item.fieldParantId + "  data-fieldId=" + item.fieldId + " >" + item.fieldName + "</option>";
				}
			})
			if(html != "") $("#firstField").show().html("<option value=''>请选择</option>" + html);
		});
		var getAuthors = function(fieldId) {
			$.post("/guidance_service/front/policies/authors/getAuthors.do", {
				fieldId
			}, function(resp) {
				var data = resp.data || []
				var html = "";
				data.forEach((item) => {
					html += "<option value=" + item.authorsName + '#' + item.priority + " data-authorsId=" + item.authorsId + "  data-authorsName=" + item.authorsName + " >" + item.authorsName + "</option>";
				});
				if(html != "") {
					$("#authors").show().html("<option value=''>请选择</option>" + html);
				} else {
					$("#authors").hide().empty();
				}
			});
		}
		$("#firstField").change(function() {
			if(this.value == "") {
				$("#secondField").hide().empty()
				$("#thirdField").hide().empty()
				$("#fourthField").hide().empty()
			} else {
				var firstField = this.value
				var html = "";
				fields.forEach(function(item) {
					if(item.fieldParantId == firstField) {
						html += "<option value=" + item.fieldId + " data-fieldParantId=" + item.fieldParantId + "  data-fieldId=" + item.fieldId + " >" + item.fieldName + "</option>";
					}
				})
				if(html != "") {
					$("#secondField").show().html("<option value=''>请选择</option>" + html);
				} else {
					$("#secondField").hide().empty()
					$("#thirdField").hide().empty()
					$("#fourthField").hide().empty()
				}
				getAuthors(firstField);
			}
		});
		$("#secondField").change(function() {
			if(this.value == "") {
				$("#thirdField").hide().empty()
				$("#fourthField").hide().empty()
			} else {
				var secondField = this.value
				var html = "";
				fields.forEach(function(item) {
					if(item.fieldParantId == secondField) {
						html += "<option value=" + item.fieldId + " data-fieldParantId=" + item.fieldParantId + "  data-fieldId=" + item.fieldId + " >" + item.fieldName + "</option>";
					}
				})
				if(html != "") {
					$("#thirdField").show().html("<option value=''>请选择</option>" + html);
				} else {
					$("#thirdField").hide().empty()
					$("#fourthField").hide().empty()
				}
				getAuthors(secondField);
			}
		});
		$("#thirdField").change(function() {
			if(this.value == "") {
				$("#fourthField").hide().empty()
			} else {
				var thirdField = this.value
				var html = "";
				fields.forEach(function(item) {
					if(item.fieldParantId == thirdField) {
						html += "<option value=" + item.fieldId + " data-fieldParantId=" + item.fieldParantId + "  data-fieldId=" + item.fieldId + " >" + item.fieldName + "</option>";
					}
				})
				if(html != "") {
					$("#fourthField").show().html("<option value=''>请选择</option>" + html);
				} else {
					$("#fourthField").hide().empty()
				}
				getAuthors(thirdField);
			}
		});
		
		$("#authors").change(function() {
			if(this.value != "") {
				$("#selectedAuthors").append("<li onclick='$(this).remove()' style='float: left;cursor: pointer;'><div data-value="+this.value+">"+this.value.split("#")[0]+"</div></li>")
			}
		});

		UE.getEditor('context');
		$("#submit").click(function() {
			var titles = $("#titles").val();
			if(!titles || titles.length == 0) {
				$("#tip").show().html("请填写标题");
				return false;
			}
			var keyword = $("#keyword").val();
			if(!keyword || keyword.length == 0) {
				$("#tip").show().html("请填写文号");
				return false;
			}
			keyword = keyword.replace(/[【《＜﹝<\[«‹〈{［「｛〖『]/g, "〔");
			keyword = keyword.replace(/[】》＞﹞>\]»›〉}］」｝〗』]/g, "〕");

			var fourthField = $("#fourthField").val();
			var thirdField = $("#thirdField").val();
			var secondField = $("#secondField").val();
			var firstField = $("#firstField").val();
			var fieldId = fourthField ? fourthField : (thirdField ? thirdField : (secondField ? secondField : firstField))
			if(!fieldId || fieldId.length == 0) {
				$("#tip").show().html("请选择法规分类");
				return false;
			}
			var authors ="";
			$("#selectedAuthors").find("div").each(function(index,item){
				authors += $(item).data("value")+";";
			})
			if(!authors || authors.length == 0) {
				$("#tip").show().html("请选择发文机关");
				return false;
			}
			var openTime = $("#openTime").val();
			if(!openTime || openTime.length == 0) {
				$("#tip").show().html("请选择发布时间");
				return false;
			}
			var effectiveTime = $("#effectiveTime").val();
			if(!effectiveTime || effectiveTime.length == 0) {
				$("#tip").show().html("请选择生效时间");
				return false;
			}
			var timeliness = $("#timeliness").val();
			var context = UE.getEditor('context').getContent()
			if(!context || context.length == 0) {
				$("#tip").show().html("请填写内容");
				return false;
			}
			var obj ={
				"titles": titles,
				"keyword": keyword,
				"fieldId": fieldId,
				"authors": authors,
				"openTime": openTime,
				"effectiveTime": effectiveTime,
				"timeliness": timeliness,
				"context": context
			}
			$.post("/guidance_service/front/me/share/policies/add.do",obj, function(data) {
				if(data.resultCode ==200){
					alert(data.message)
					window.location.href="/ceca_two/modules/share/index.html";
				}else{
					alert(data.message)
				}
			});
		});
	});
</script>
</body>

</html>